/*
 * DShowDeviceGraph.h
 *
 *  Created on: 2011-10-16
 *      Author: terry
 */

#ifndef DSHOWDEVICEGRAPH_H_
#define DSHOWDEVICEGRAPH_H_

#include "DShowGraph.h"
#include "SampleGrabberCallback.h"
#include <vector>

namespace av
{
typedef std::vector< String >       StringArray;
}



class DShowDeviceGraph: public DShowGraph
{
public:
    DShowDeviceGraph();
    virtual ~DShowDeviceGraph();

    virtual HRESULT buildGraph();
    virtual void destroyGraph();
    virtual int queryMediaFormat(av::MediaFormat& fmt);

    virtual ISampleGrabber* getVideoGrabber();
    virtual ISampleGrabber* getAudioGrabber();


    int setVideoDevice(const char* name, int index);
    int setAudioDevice(const char* name, int index);

    int setVideoStreamInfo(int width, int height, int fps);
    int getVideoStreamInfo(int& width, int& height, int& fps);

    HRESULT getAudioStreamInfo(int& channels, int& sampleRate, int& bits);
    HRESULT setAudioStreamInfo(int channels, int sampleRate, int bits);

    int setVolume(double volume);
    int getVolume(double* pVolume);

    int enumAudioLine(av::StringArray& array);
    const char* getCurAudioLine();
    int setAudioLine(const char* name);

    bool existVideo();
    bool existAudio();

    IAMStreamConfigPtr queryVideoStreamConfig();
    IAMStreamConfigPtr queryAudioStreamConfig();

    HRESULT getVideoSizeCaps(SIZE& sizeMin, SIZE& sizeMax);

    void  disconnect();


    bool setVideoWindow(HWND hwnd);

    void showVideoWindow(bool visible);

    bool isVideoWindowVisible();

    size_t findIndex(GUID* subtypes, size_t maxCount, const GUID& guid);

    int setVideoSubType(GUID* subtypes, size_t maxCount);

    int setVideoSubType(GUID subtype);

    size_t getVideoAvailableSubType(GUID* subtypes, size_t maxCount);

protected:
    HRESULT buildVideoGraph();
    HRESULT buildAudioGraph();

    HRESULT disableVideoWindow();


    HRESULT makeVideoGrabFilter();
    HRESULT makeAudioGrabFilter();

    IBaseFilter* queryAudioSrcFilter();
    IPin* queryAudioPin(LPCWSTR name);
    IAMAudioInputMixer* queryAudioMixer(LPCWSTR name);
    IAMAudioInputMixer* queryCurrentAudioMixer();

protected:
    std::string  m_videoDeviceName;
    int m_videoDeviceIndex;

    std::string  m_audioDeviceName;
    int m_audioDeviceIndex;

    IBaseFilter*    m_iVideoSrcFilter;
    IBaseFilter*    m_iAudioSrcFilter;

    IBaseFilter*    m_pVideoGrabFilter;
    IBaseFilter*    m_pAudioGrabFilter;

    ISampleGrabber* m_iVideoGrabber;
    ISampleGrabber* m_iAudioGrabber;
    
    IBaseFilter*    m_iVideoRender;

    std::string    m_curAudioLine;

    VideoGrabberCallback*   m_pVideoCallback;
    AudioGrabberCallback*   m_pAudioCallback;

};

#endif /* DSHOWDEVICEGRAPH_H_*/
